#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int count = 1;
    int child;
    printf("Before create son, teh father's count is: %d\n", count); //创建进程之前
    child = vfork();
    if (child < 0)
    {
        printf("error in vfork\n");
        exit(1);
    }
    if (child == 0)
    {
        printf("This is son, his pid is: %d and the count is: %d\n", getpid(), ++count);
        exit(1);
    }
    else
        printf("After son, This is father, his pid is: %d and the count is: %d, and the child is: %d\n", getpid(), count, child);
    return 0;
}